package routes

import (
	"github.com/gin-gonic/gin"
	swaggerfiles "github.com/swaggo/files"
	ginSwagger "github.com/swaggo/gin-swagger"
	"lisGin/api"
	docs "lisGin/docs"
	"lisGin/middle"
	"net/http"
)

func Init() *gin.Engine {
	// 注册路由
	r := gin.Default()
	auth := r.Group("/api")
	docs.SwaggerInfo.BasePath = "/api"
	r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerfiles.Handler))
	auth.Use(middle.JWTAuthMiddleware())
	{
		auth.POST("testJwt", func(c *gin.Context) {
			c.JSON(http.StatusOK, gin.H{
				"message": "success",
			})
		})
	}
	r.GET("/ping", api.Ping)
	r.POST("/api/login", api.Login)
	r.POST("/api/register", api.Register)

	return r
}
